package com.ruoyi.wx.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.ChannelSort;
import com.ruoyi.system.service.IChannelSortService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ChannelBlog;
import com.ruoyi.system.service.IChannelBlogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 渠道博客Controller
 * 
 * @author yanghuiliao
 * @date 2022-12-02
 */
@RestController
@RequestMapping("/wx/blog")
public class ChannelBlogController extends BaseController
{
    @Autowired
    private IChannelBlogService channelBlogService;

    @Autowired
    private IChannelSortService channelSortService;

    @PostMapping("/listType")
    public AjaxResult list(@RequestBody ChannelSort channelSort)
    {
        List<ChannelSort> channelSorts = channelSortService.selectChannelSortList(channelSort);
        return AjaxResult.success(channelSorts);
    }

    /**
     * 查询渠道博客列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ChannelBlog channelBlog)
    {
        startPage();
        List<ChannelBlog> list = channelBlogService.selectChannelBlogList(channelBlog);
        return getDataTable(list);
    }

    /**
     * 导出渠道博客列表
     */
    @Log(title = "渠道博客", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChannelBlog channelBlog)
    {
        List<ChannelBlog> list = channelBlogService.selectChannelBlogList(channelBlog);
        ExcelUtil<ChannelBlog> util = new ExcelUtil<ChannelBlog>(ChannelBlog.class);
        return util.exportExcel(list, "blog");
    }

    /**
     * 获取渠道博客详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(channelBlogService.selectChannelBlogById(id));
    }

    /**
     * 新增渠道博客
     */
    @PreAuthorize("@ss.hasPermi('system:blog:add')")
    @Log(title = "渠道博客", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelBlog channelBlog)
    {
        return toAjax(channelBlogService.insertChannelBlog(channelBlog));
    }

    /**
     * 修改渠道博客
     */
    @PreAuthorize("@ss.hasPermi('system:blog:edit')")
    @Log(title = "渠道博客", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelBlog channelBlog)
    {
        return toAjax(channelBlogService.updateChannelBlog(channelBlog));
    }

    /**
     * 删除渠道博客
     */
    @PreAuthorize("@ss.hasPermi('system:blog:remove')")
    @Log(title = "渠道博客", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(channelBlogService.deleteChannelBlogByIds(ids));
    }
}
